home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2 Examples.sit / Raven 1.2 Examples / Skeleton / Source / Main.cpp < prev    next >
C/C++ Source or Header  |  1997-08-16  |  5KB  |  190 lines

  1. /*
  2.  *  File:       Main.cpp
  3.  *  Summary:       The big enchilada.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996-1997 Jesse Jones. All Rights Reserved.
  7.  *
  8.  *  Change History (most recent first):    
  9.  *
  10.  *         <2>     8/15/97    JDJ        Added code to main to dump object heap info in
  11.  *                                    non-debug, non-release builds.
  12.  *         <1>     2/24/96    JDJ        Created.
  13.  */
  14.  
  15. #include <List.h>
  16.  
  17. #include <List.h>
  18.  
  19. #include <ZAppBootStrap.h>
  20. #include <ZFloatingDesktop.h>
  21. #include <ZGestalt.h>
  22. #include <ZPreferences.h>
  23. #include <ZStringUtils.h>
  24.  
  25. #if RAVEN_OPERATOR_NEW
  26. #include <ZBestFitAllocator.h>
  27. #include <ZMemoryHeap.h>
  28. #include <ZNewAndDelete.h>
  29. #include <ZSimpleAllocator.h>
  30. #endif
  31.  
  32. #include "App.h"
  33.  
  34.  
  35. // ===================================================================================
  36. //    class TBootStrap
  37. // ===================================================================================
  38.  
  39. //---------------------------------------------------------------
  40. //
  41. // TBootStrap::DoEarlyInit
  42. //
  43. // This is called after the toolbox is initialized, but before
  44. // static objects are constructed. You shouldn't have to do
  45. // anything besides creating the object heap here. (Use OnBoot
  46. // if you need to initialize other things).
  47. //
  48. //---------------------------------------------------------------
  49. void TBootStrap::DoEarlyInit()
  50. {
  51.     const long  kInitialObjectHeapSize   = 500*1024L;    // ・・・ハadjust these numbers (using the Dump Object Heap command in the Debug menu)
  52.     const long  kObjectHeapIncrementSize = 32*1024L;        
  53.     const short    kNumMasterPtrBlocks      = 10;
  54.  
  55.     for (short i = 1; i <= kNumMasterPtrBlocks; i++)
  56.         MoreMasters();
  57.  
  58. #if RAVEN_OPERATOR_NEW                                    // on by default
  59.     ASSERT(gObjectHeap == nil);
  60.     
  61.     TAllocator* alloc = new TBestFitAllocator(kInitialObjectHeapSize, kObjectHeapIncrementSize);
  62.     gObjectHeap = new TMemoryHeap(alloc);
  63.  
  64. #else
  65.     _prealloc_newpool(kInitialObjectHeapSize);
  66.     _set_newpoolsize(kObjectHeapIncrementSize);
  67.     _set_newnonptrmax(kObjectHeapIncrementSize/4);
  68. #endif
  69. }
  70.  
  71. #pragma mark -
  72.  
  73. // ===================================================================================
  74. //    class CMyBooter
  75. //        TAppBootStrap initializes some of the core Raven classes and checks to make
  76. //        sure the machine is capable of running your app.
  77. // ===================================================================================
  78. class CMyBooter : public TAppBootStrap {
  79.     
  80.     typedef TAppBootStrap Inherited;
  81.     
  82. //-----------------------------------
  83. //    Initialization/Destruction
  84. //
  85. public:
  86.     virtual             ~CMyBooter();
  87.     
  88.                           CMyBooter();
  89.  
  90. //-----------------------------------
  91. //    Inherited API
  92. //
  93. protected:
  94.     virtual void         OnSystemNeeds(list<string, allocator<string> >& needs);
  95.  
  96.     virtual void         OnBoot();
  97. };
  98.  
  99.  
  100. //---------------------------------------------------------------
  101. //
  102. // CMyBooter::~CMyBooter
  103. //
  104. //---------------------------------------------------------------
  105. CMyBooter::~CMyBooter()
  106. {
  107. }
  108.  
  109.  
  110. //---------------------------------------------------------------
  111. //
  112. // CMyBooter::CMyBooter
  113. //
  114. //---------------------------------------------------------------
  115. CMyBooter::CMyBooter()
  116. {
  117.     mIdealDisplayMode = SDisplayMode(640, 480, 8);
  118. }
  119.  
  120.  
  121. //---------------------------------------------------------------
  122. //
  123. // CMyBooter::OnSystemNeeds
  124. //
  125. // If your app requires things that aren't on every machine (eg
  126. // QuickDraw 3D, the Drag Manager, etc) add a test here. TBootStrap
  127. // will popup a dialog listing all of the items that are missing
  128. // from the user's machine.
  129. //
  130. //---------------------------------------------------------------
  131. void CMyBooter::OnSystemNeeds(list<string, allocator<string> >& needs)
  132. {
  133.     Inherited::OnSystemNeeds(needs);
  134.  
  135. //    if (!UGestalt::hasDragMgr)
  136. //        needs.push_back(LoadAppString("the Drag Manager"));            
  137. }
  138.  
  139.  
  140. //---------------------------------------------------------------
  141. //
  142. // CMyBooter::OnBoot
  143. //
  144. // This is the best place to initialize stuff.
  145. //
  146. //---------------------------------------------------------------
  147. void CMyBooter::OnBoot()
  148. {
  149.     Inherited::OnBoot();
  150.  
  151.     // Aplications often have just a few block sizes that account
  152.     // for the bulk of their operator new allocations. You can 
  153.     // speed up operator new by calling AddAllocator for these
  154.     // common sizes. (You can find the most used block sizes by
  155.     // using the "Dump Object Heap" command in the Debug menu).
  156.     gObjectHeap->AddAllocator(20, 800);
  157.  
  158.     TFloatingDesktop::Init();    
  159.  
  160.     UPreferences::Init(LoadAppString("Skeleton Prefs"), 'SKEL');
  161. }
  162.  
  163. #pragma mark -
  164.  
  165. //---------------------------------------------------------------
  166. //
  167. // Main
  168. //
  169. //---------------------------------------------------------------
  170. void main()
  171. {
  172.     CMyBooter booter;
  173.     booter.Boot();
  174.             
  175.     {
  176.     CApplication theApp;
  177.         theApp.Run();                    
  178.     }
  179.  
  180. #if RAVEN_OPERATOR_NEW && !DEBUG && !RELEASE
  181.     // Object sizes can change in release builds. If they do the
  182.     // fixed allocators may need to be adjusted. To check for this
  183.     // you should run a non-debug, non-release version of the app.
  184.     gObjectHeap->DumpCommonBlocks();
  185.     gObjectHeap->DumpAllocatorCapacities();
  186. #endif
  187. }
  188.  
  189.  
  190.